from rest_framework.generics import ListAPIView, ListCreateAPIView
from apps.users.models import User
from apps.meiduo_admin.serializers.user import UserSerializer
from apps.meiduo_admin.utils import PageNum


class UserListView(ListCreateAPIView):
    # queryset = User.objects.all()
    serializer_class = UserSerializer
    pagination_class = PageNum

    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword:
            return User.objects.filter(username__contains=keyword)
        return User.objects.all()

